﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSM.Lib.Protocol
{
	/// <summary>
	/// 用户登录
	/// </summary>
	public class UserLoginReq : ProtocolReqBase
	{
		public enum LoginReqType
		{
			UserID,
			NickName,
			Email
		}
		public UserLoginReq() : base(ProtocolWord.UserLoginReq) { }
		public LoginReqType ReqType;
		public string LoginKey;	//用户昵称
		public string Password;	//密码
		public Int32 ClientVer = 0x100;	//客户端版本

		public override ProtocolBase Response(UserInfo ui)
		{
			return new UserLoginResp().Response(ui);
		}
	}
	/// <summary>
	/// LoginUser命令的服务器回应
	/// </summary>
	public class UserLoginResp : ProtocolRespBase
	{
		public UserLoginResp() : base(ProtocolWord.UserLoginResp) { }
		public int Result;
		public string Message;

		public override ProtocolBase Response(object o)
		{
			UserInfo ui = o as UserInfo;

			if (ui.UserID == 0)	//用户存在但密码不对
			{
				Message = "登录失败 ：密码错误";
				Result = 0;
			}
			else
			{
				if (ui.IsFreeze)
				{
					Message = "登录失败 ：用户" + ui.NickName + "被冻结";
					Result = 0;
				}
				else if (ui.IsLogoff)
				{
					Message = "登录失败 ：用户" + ui.NickName + "已注销";
					Result = 0;
				}
				else
				{
					Message = "登录成功，欢迎" + ui.NickName;
					Result = 1;
				}
			}

			return this;
		}
	}
}
